<?php echo $header; ?>
<div class="alert-wrap">
    <div class="alert-message alert-position alert-fixed"></div>
</div>
<div class="container in-wrap">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <h1 class="text-center"><?php echo $maincontent; ?></h1>
            <?php if ($messages) { ?>
            <!-- <div><?php print_r($messages); ?></div> -->
            <?php foreach($messages as $message) { ?>
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <?php echo $message['nickname']; ?>
                </div>
                <div class="panel-body">
                    <?php echo $message['content']; ?>
                </div>
                <ul class="list-group">
                    <?php foreach($message['replay'] as $replay) { ?>
                    <li class="list-group-item">
                        <div class="panel panel-info panel-inner">
                            <div class="panel-heading">
                                <span><?php echo $replay['nickname']; ?></span>
                                <span>回复</span>
                                <span><?php echo $replay['rnickname']; ?></span>
                            </div>
                            <div class="panel-body">
                                <?php echo $replay['content']; ?>
                            </div>
                            <div class="panel-footer">
                                <span>发布时间:</span>
                                <span><?php echo $replay['send_time']; ?></span>
                                <span>
                                         <button class="btn btn-default btn-message-replay" data-id="<?php echo $message['id']; ?>" data-user_id="<?php echo $replay['muser_id']; ?>">回复</button>
                                     </span>
                            </div>
                        </div>
                    </li>
                    <?php } ?>
                    <!-- <li class="list-group-item">
                         <div class="panel panel-info panel-inner">
                             <div class="panel-heading">
                                 <span>东华帝君</span>
                                 <span>回复</span>
                                 <span>王重阳</span>
                             </div>
                             <div class="panel-body">
                                 首先，我非常赞同阅读原版文章是最佳的背单词途径。但是反过来说，你背单词是为啥？难道不是为了能高效阅读原版文章吗？OK，死循环。所以你必须先从一个方向学起，才能挤进这个“单词-阅读”的循环当中，自然要求你必先掌握一定量的词汇基础。其次，抛开效率谈学习都是耍流氓有些人就是为了考试。我三个月后要考托福，要考GRE，现在你跟我说慢慢阅读然后积累词汇量？excuse me?掌握同样数量的单词到同样程度，我相信我的方法可以让你节约很多时间和精力。这是本文最大的价值。
                             </div>
                             <div class="panel-footer">
                                 <span>发布时间:</span>
                                 <span>2017年4月25日16:45:46</span>
                                 <span>
                                     <button class="btn btn-default btn-message-replay">回复</button>
                                 </span>
                             </div>
                         </div>
                     </li>
                     <li class="list-group-item">
                         <div class="panel panel-info panel-inner">
                             <div class="panel-heading">
                                 <span>王重阳</span>
                                 <span>回复</span>
                                 <span>东华帝君</span>
                             </div>
                             <div class="panel-body">
                                 首先，我非常赞同阅读原版文章是最佳的背单词途径。但是反过来说，你背单词是为啥？难道不是为了能高效阅读原版文章吗？OK，死循环。所以你必须先从一个方向学起，才能挤进这个“单词-阅读”的循环当中，自然要求你必先掌握一定量的词汇基础。其次，抛开效率谈学习都是耍流氓有些人就是为了考试。我三个月后要考托福，要考GRE，现在你跟我说慢慢阅读然后积累词汇量？excuse me?掌握同样数量的单词到同样程度，我相信我的方法可以让你节约很多时间和精力。这是本文最大的价值。
                             </div>
                             <div class="panel-footer">
                                 <span>发布时间:</span>
                                 <span>2017年4月25日16:45:46</span>
                                 <span>
                                     <button class="btn btn-default btn-message-replay">回复</button>
                                 </span>
                             </div>
                         </div>
                     </li> -->
                </ul>
                <div class="panel-footer">
                    <span>发布时间:</span>
                    <span><?php echo $message['send_time']; ?></span>
                    <span>
                            <button class="btn btn-default btn-message-replay" data-id="<?php echo $message['id']; ?>" data-user_id="<?php echo $message['muser_id']; ?>">回复</button>
                        </span>
                </div>
            </div>
            <?php } ?>
            <?php } ?>
            <div class="nav" aria-label="Page navigation">
                <div class="center-wrap">
                    <div class="center-inner pagination-html">
                        <!-- <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <li>
                                    <a href="#" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                                <li><a href="#">1</a></li>
                                <li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li>
                                    <a href="#" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav> -->
                        <?php echo $pagination; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="container m-btn-wrap">
    <div class="row">
        <div class="col-md-12">
            <div class="center-wrap">
                <div class="center-inner">
                    <button class="btn btn-primary" id="m-btn-publish">发布意见和建议</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 发布模态框 -->
<div class="modal fade" id="m-publish-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <div class="alert alert-warning text-center m-p-alert">
                </div>
                <h4 class="modal-title" id="m-p-title">发布意见和建议</h4>
            </div>
            <div class="modal-body">
                <img src="admin\view\image\loading\sixnew.gif" class="img-responsive img-center detailloading" alt="Responsive image">
                <form class="form-horizontal" method="post" action="" id="m-p--form">
                    <div class="form-group from-margin-top">
                        <label for="" class="control-label col-md-2 col-md-offset-1">类别</label>
                        <div class="col-md-6">
                            <select class="form-control" id="message-type">
                                <option selected="ture"></option>
                                <option>意见</option>
                                <option>建议</option>
                                <option>其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group from-margin-top">
                        <div class="col-md-6">
                            <textarea name="m-n-content" id="m-content"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="m-p-close">关闭</button>
                <a href="javascript:void(0);" class="btn btn-primary" id="m-p-submit">保存</a>
            </div>
        </div>
    </div>
</div>
<?php echo $footerin;?>
<script type="text/javascript">
$(function() {
    //模态框触发
    $("#m-btn-publish,.btn-message-replay").click(function() {
        $("#m-publish-modal").modal();
    })
    $(".btn-message-replay").click(function(){
        var id=$(this).data("id");
        var user_id = $(this).data("user_id");
        var $submit=$("#m-p-submit");
        $submit.data("id",id);
        $submit.data("user_id",user_id);
        $("#m-publish-modal").modal();
    })
    //关闭操作
    $("#m-publish-modal").on("hidden.bs.modal", function(e) {
            window.location.reload();
        })
    //提交消息
    $("#m-p-submit").click(function() {
        var mrid,ruser_id;
        var user_id = "<?php echo $user_id; ?>";
        var $m_p_alert = $(".m-p-alert");
        var $m_alert = $(".alert-message");
        var content = $("#m-content").val();
        var type = $("#message-type").val();
        var data = {
                    content: content,
                    type: type
                };
        if(mrid =$(this).data("id")){
             data.mrid = mrid;
        }
        if(ruser_id =$(this).data("user_id")){
             data.ruser_id = ruser_id;
        }
        if(ruser_id == user_id){
            alert2000($m_p_alert, "自己不能回复自己", 2);
            return false;
        }
        if (content === "") {
            alert2000($m_p_alert, "请填写内容", 2);
            return false;
        }
        if (type === "") {
            alert2000($m_p_alert, "请选择类别", 2);
            return false;
        }
        type = (type == "意见" && 1) || (type == "建议" && 2) || (type == "其他" && 3);
        $.ajax({
                type: "POST",
                dataType: "json",
                url: "<?php echo $addmessageurl; ?>",
                data: data,
                beforeSend: function() {
                    $(".detailloading").css("display", "block");
                },
                success: function(data) {
                    // $("#remind-complate-detail").off("shown.bs.modal");
                    $(".detailloading").css("display", "none");
                    $("#m-publish-modal").modal('hide');
                    alert2000($m_alert, "恭喜您，成功发布了一条信息！");
                }
            }) //ajax
    })
})
</script>
<?php echo $footer;?>
